#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.web.config;


import ${package}.service.common.BizResult;
import ${package}.service.common.ErrorCode;
import ${package}.service.common.ErrorMessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by well on 2017/11/18.
 */
@ControllerAdvice
public class GlobalDefaultExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(GlobalDefaultExceptionHandler.class);

    @Autowired
    private ErrorMessageHandler errorMessageHandler;

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public BizResult defaultErrorHandler(HttpServletRequest req, Exception e) {
        logger.error("uncatch exception", e);
        BizResult bizResult = new BizResult();
        String message = errorMessageHandler.getMessage(ErrorCode.UNKOWN_ERROR.name());
        bizResult.setCode(ErrorCode.UNKOWN_ERROR.getCode());
        bizResult.setMsg(message);
        return bizResult;
    }
}
